package com.start.cas;


import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.List;
import java.util.Optional;

@Data
@Configuration
@ConfigurationProperties(prefix = "start.cas")
public class StartCasClientsConfig {
    private Boolean enable;
    private List<StartCasClient> clients;

    public boolean hasClient(String appId) {
        if (!enable || clients == null || clients.isEmpty()) {
            return false;
        }
        return clients.stream().anyMatch(e -> e.getAppId().equals(appId));
    }

    /**
     * 获取客户端配置
     *
     * @param appId appId
     * @return
     */
    public StartCasClient getClientConfig(String appId) {
        Optional<StartCasClient> casClient = clients.stream().filter(e -> e.getAppId().equals(appId)).findFirst();
        return casClient.orElse(null);
    }
}
